package com.ybcj.controller;

import com.ybcj.pojo.Address;
import com.ybcj.pojo.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试响应结果
 */

@RestController
public class ResponseController {
    // 返回字符串
    @RequestMapping("/hello")
    public String hello(){
        System.out.println("Hello World ~");
        return "Hello World ~";
    }

    // 返回对象
    @RequestMapping("/getAddr")
    public Address getAddr(){
        Address addr = new Address();
        addr.setProvince("四川");
        addr.setCity("成都");

        return addr;
    }

    // 返回集合
    @RequestMapping("/listAddr")
    public List<Address> listAddr(){
        List<Address> addrs = new ArrayList<>();
        Address addr1 = new Address();
        addr1.setProvince("四川");
        addr1.setCity("成都");

        Address addr2 = new Address();
        addr2.setProvince("四川");
        addr2.setCity("宜宾");

        addrs.add(addr1);
        addrs.add(addr2);

        return addrs;
    }

    // 统一响应结果
    @RequestMapping("/helloResult")
    public Result helloResult(){
        return Result.success("Hello World ~");
    }

    // 返回对象
    @RequestMapping("/getAddrResult")
    public Result getAddrResult(){
        Address addr = new Address();
        addr.setProvince("四川");
        addr.setCity("成都");

        return Result.success(addr);
    }

    // 返回集合
    @RequestMapping("/listAddrResult")
    public Result listAddrResult(){
        List<Address> addrs = new ArrayList<>();
        Address addr1 = new Address();
        addr1.setProvince("四川");
        addr1.setCity("成都");

        Address addr2 = new Address();
        addr2.setProvince("四川");
        addr2.setCity("宜宾");

        addrs.add(addr1);
        addrs.add(addr2);

        return Result.success(addrs);
    }
}
